/* GUI CONVERTED from rcccmt.p (converter v1.75) Tue Apr 10 12:03:28 2001 */
/* rcccmt.p - Release Management Customer Schedules                           */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.6.1.6 $                                                         */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3     LAST MODIFIED: 09/30/92    BY: WUG *G462*                */
/* Oracle changes (share-locks)     09/12/94    BY: rwl *GM44*                */
/* REVISION: 7.3     LAST MODIFIED: 09/20/94    BY: ljm *GM74*                */
/* REVISION: 7.3     LAST MODIFIED: 10/19/94    BY: ljm *GN40*                */
/* REVISION: 7.3     LAST MODIFIED: 11/18/94    BY: dpm *GO55*                */
/* REVISION: 7.3     LAST MODIFIED: 12/15/94    BY: rxm *GN16*                */
/* REVISION: 7.3     LAST MODIFIED: 01/26/95    BY: rxm *G0D5*                */
/* REVISION: 7.3     LAST MODIFIED: 03/29/95    BY: bcm *G0JS*                */
/* REVISION: 7.3     LAST MODIFIED: 03/20/96    BY: kjm *G1R2                 */
/* REVISION: 8.6E    LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane           */
/* REVISION: 8.6E    LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan          */
/* REVISION: 8.6E    LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan          */
/* REVISION: 9.0     LAST MODIFIED: 02/24/99   BY: *J3BR* Anup Pereira        */
/* REVISION: 9.0     LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan          */
/* REVISION: 9.1     LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane    */
/* REVISION: 9.1     LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown          */
/* REVISION: 9.1     LAST MODIFIED: 09/05/00   BY: *N0R9* BalbeerS Rajput     */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Old ECO marker removed, but no ECO header exists *G1R2*                    */
/* $Revision: 1.6.1.6 $    BY: Jean Miller    DATE: 03/22/01 ECO: *P008*        */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* CUSTOMER CALENDAR INQUIRY */

{mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rcccmt_p_1 "Description"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcccmt_p_3 "Customer/Ship-To"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcccmt_p_7 "Monday"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcccmt_p_8 "Friday"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcccmt_p_9 "Saturday"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcccmt_p_10 "Sunday"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcccmt_p_11 "Tuesday"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcccmt_p_13 "Thursday"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcccmt_p_14 "Wednesday"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define variable del-yn like mfc_logical initial no.
define variable daylabel as character format "x(10)".
define variable disp-work-day as character no-undo.
define variable disp-hours    as character format "x(9)" no-undo.
define variable w-days        as character no-undo.

define buffer soddet for sod_det.

disp-work-day = getTermLabel("WORK_DAY",8).
disp-hours    = getTermLabelRt("HOURS",9).
w-days        = getTermLabel("SUNDAY",10) + "," .
w-days        = w-days + getTermLabel("MONDAY",10) + ",".
w-days        = w-days + getTermLabel("TUESDAY",10) + ",".
w-days        = w-days + getTermLabel("WEDNESDAY",10) + ",".
w-days        = w-days + getTermLabel("THURSDAY",10) + ",".
w-days        = w-days + getTermLabel("FRIDAY",10) + ",".
w-days        = w-days + getTermLabel("SATURDAY",10).


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
shop_site  colon 25 label {&rcccmt_p_3}
   ad_name             no-label
   skip(1)
   disp-work-day       no-label at 25
   disp-hours          no-label       at 39   
   skip
   shop_wdays[1]  label {&rcccmt_p_10} colon 25 space(8)
   shop_hours[1]  no-label
   shop_wdays[2]  label {&rcccmt_p_7}  colon 25 space(8)
   shop_hours[2]  no-label
   shop_wdays[3]  label {&rcccmt_p_11} colon 25 space(8)
   shop_hours[3]  no-label
   shop_wdays[4]  label {&rcccmt_p_14} colon 25 space(8)
   shop_hours[4]  no-label
   shop_wdays[5]  label {&rcccmt_p_13} colon 25 space(8)
   shop_hours[5]  no-label
   shop_wdays[6]  label {&rcccmt_p_8}  colon 25 space(8)
   shop_hours[6]  no-label
   shop_wdays[7]  label {&rcccmt_p_9}  colon 25 space(8)
   shop_hours[7]  no-label
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80
 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = (getFrameTitle("CUSTOMER_CALENDAR",25)).
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
cal_ref        colon 25
   cal_start      colon 25 skip (1)
   cal_end        colon 25
   cal_hours
 SKIP(.4)  /*GUI*/
with frame b width 80 attr-space side-labels
 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-b-title AS CHARACTER.
 F-b-title = (getFrameTitle("OPERATING_DAY_HOUR_EXCEPTIONS",41)).
 RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame b =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame b + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame b =
  FRAME b:HEIGHT-PIXELS - RECT-FRAME:Y in frame b - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME b = FRAME b:WIDTH-CHARS - .5. /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame b:handle).

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
hd_date       colon 25
   skip(1)
   hd_desc       colon 25 label {&rcccmt_p_1}
        skip space(2) daylabel   
 SKIP(.4)  /*GUI*/
with frame c width 80 attr-space side-labels
 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-c-title AS CHARACTER.
 F-c-title = (getFrameTitle("NON-OPERATING_DAYS",26)).
 RECT-FRAME-LABEL:SCREEN-VALUE in frame c = F-c-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame c =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame c + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame c =
  FRAME c:HEIGHT-PIXELS - RECT-FRAME:Y in frame c - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME c = FRAME c:WIDTH-CHARS - .5. /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame c:handle).

mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


   display
      disp-work-day
      disp-hours
   with frame a.

   do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.


      prompt-for shop_site with frame a
      editing:

         {mfnp01.i ls_mstr
            shop_site ls_addr ""custcal"" ls_type ls_type}

         if frame-field = "shop_site" then global_addr = frame-value.

         if recno <> ? then do:
            find shop_cal where
                 shop_site = ls_addr and
                 shop_wkctr = "" and
                 shop_mch = ""
            no-lock no-error.
            if available shop_cal then do:
               find ad_mstr no-lock where ad_addr = shop_site no-error.
               display
                  shop_site
                  ad_name when (available ad_mstr)
                  ""      when (not available ad_mstr) @ ad_name
                  shop_wdays
                  shop_hours
               with frame a.
            end.
         end.

      end. /* prompt-for editing */

      find ad_mstr where ad_addr = input frame a shop_site
      no-lock no-error.

      if available ad_mstr then do:

         find ls_mstr where
              ls_addr = ad_addr and
              ls_type = "customer"
         no-lock no-error.

         if not available ls_mstr then do:
            find ls_mstr where
                 ls_addr = ad_addr and
                 ls_type = "ship-to"
            no-lock no-error.
         end.
      end.
      if not available ad_mstr or not available ls_mstr
      then do:
         /* Ship-To does not exist */
         {pxmsg.i &MSGNUM=8501 &ERRORLEVEL=3}
         undo , retry.
      end.

      find shop_cal where
           shop_site = input frame a shop_site and
           shop_wkctr = "" and
           shop_mch = ""
      exclusive-lock no-error.

      if not available shop_cal then
      do with frame a:

         /* Adding new Record */
         {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}

         find ls_mstr where
              ls_addr = input shop_site and
              ls_type = "custcal"
         no-lock no-error.

         if not available ls_mstr then do:
            create ls_mstr.
            assign
               ls_addr = input shop_site
               ls_type = "custcal".
         end.

         create shop_cal.
         assign
            shop_site
            shop_wkctr = ""
            shop_mch = ""
            shop_wdays[1] = no
            shop_wdays[2] = yes
            shop_wdays[3] = yes
            shop_wdays[4] = yes
            shop_wdays[5] = yes
            shop_wdays[6] = yes
            shop_wdays[7] = no
            shop_hours[1] = 0
            shop_hours[2] = 8
            shop_hours[3] = 8
            shop_hours[4] = 8
            shop_hours[5] = 8
            shop_hours[6] = 8
            shop_hours[7] = 0.

      end. /* if not available shop_cal */

      find ad_mstr where ad_addr = shop_site no-lock no-error.

      display
         shop_site
         ad_name when (available ad_mstr)
         ""      when (not available ad_mstr) @ ad_name
         shop_wdays
         shop_hours
      with frame a.

      ststatus = stline[2].
      status input ststatus.

      do on error undo, retry with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


         del-yn = no.

         set
            shop_wdays
            shop_hours
         go-on ("F5" "CTRL-D").

         if lastkey = keycode("F5") or lastkey = keycode("CTRL-D")
         then do:

            del-yn = yes.
            /* Please confirm delete */
            {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn
                     &CONFIRM-TYPE='LOGICAL'}
            if not del-yn then
               undo, retry.

            if del-yn then do:

               for each cal_det where
                        cal_site = shop_site and
                        cal_wkctr = shop_wkctr and
                        cal_mch = shop_mch
               exclusive-lock:
                  delete cal_det.
               end.

               find first ls_mstr where
                          ls_type = "custcal" and
                          ls_addr = shop_site
               exclusive-lock.
               delete ls_mstr.

               delete shop_cal.

               clear frame a.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.

               del-yn = no.

               next mainloop.

            end.

         end.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* frame a */

      b-loop:
      repeat with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.


         prompt-for
            cal_ref
            cal_start
         with frame b editing:
            {mfnp05.i cal_det cal_det
               "cal_site = shop_site and
                cal_wkctr = shop_wkctr and cal_mch = shop_mch"
                cal_ref "input cal_ref"}
            if recno <> ? then
            display
               cal_ref
               cal_start
               cal_end
               cal_hours.
         end.

         find cal_det using cal_ref and cal_start
         where cal_site = shop_site
          and cal_wkctr = shop_wkctr and cal_mch = shop_mch
         no-error.

         if not available cal_det then do:
            /* Creating new record */
            {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
            create cal_det.
            assign
               cal_ref
               cal_start
               cal_site = shop_site
               cal_wkctr = shop_wkctr
               cal_mch = shop_mch.
         end.

         recno = recid(cal_det).
         display
            cal_ref
            cal_start
            cal_end
            cal_hours.

         ststatus = stline[2].
         status input ststatus.

         do on error undo , retry:
/*GUI*/ if global-beam-me-up then undo, leave.


            del-yn = no.
            set
               cal_end
               cal_hours
            go-on ("F5" "CTRL-D").

            if lastkey = keycode("F5") or lastkey = keycode("CTRL-D")
            then do:

               del-yn = yes.
               {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn
                        &CONFIRM-TYPE='LOGICAL'}

               if not del-yn then
                  undo, retry.

               if del-yn then do:
                  delete cal_det.
                  clear frame b.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
                  del-yn = no.
               end.

            end.

            else do:

               if cal_start <> ? and
                  cal_end   <> ? and
                  cal_start  > cal_end
               then do:
                  /* START DATE MUST BE PRIOR TO END DATE  */
                  {pxmsg.i &MSGNUM=4 &ERRORLEVEL=3}
                  next-prompt cal_start.
                  if batchrun = yes then
                     undo b-loop, leave b-loop.
                  else
                     undo b-loop, retry b-loop.
               end. /* IF CAL_START <> ? ... */

            end. /* ELSE DO */

         end.
/*GUI*/ if global-beam-me-up then undo, leave.


      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* repeat b */

      framecloop:
      repeat with frame c:
/*GUI*/ if global-beam-me-up then undo, leave.


         prompt-for
            hd_date
         with frame c editing:

            /* FIND NEXT/PREVIOUS RECORD */
            {mfnp05.i hd_mstr hd_mstr "hd_site = shop_site"
               hd_date "input hd_date"}

            if recno <> ? then
            display
               hd_date
               string(entry(weekday(hd_date),w-days)) @ daylabel no-label
               hd_desc.

         end.

         /* ADD/MOD/DELETE  */
         find hd_mstr where
              hd_site = shop_site and
              hd_date = input hd_date
         exclusive-lock no-error.

         if not available hd_mstr then do:
            create hd_mstr.
            assign
               hd_site = shop_site
               hd_date.
         end.

         display
            string(entry(weekday(hd_date),w-days)) @ daylabel no-label
            hd_desc.

         ststatus = stline[2].
         status input ststatus.

         do on error undo, retry with frame c:
/*GUI*/ if global-beam-me-up then undo, leave.


            del-yn = no.
            set hd_desc go-on ("F5" "CTRL-D" ).

            if lastkey = keycode("F5") or lastkey = keycode("CTRL-D")
            then do:

               del-yn = yes.
               {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn
                        &CONFIRM-TYPE='LOGICAL'}

               if not del-yn then
                  undo, retry.

               if del-yn or hd_date = ? then do:

                  delete hd_mstr.

                  display
                     "" @ hd_date
                     "" @ hd_desc
                     "" @ daylabel no-label
                  with frame c.

                  del-yn = no.

                  next framecloop.

               end.

            end.

         end.
/*GUI*/ if global-beam-me-up then undo, leave.


      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* repeat c */

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* transaction */

   /* TURN ON SCHEDULE CHANGE FLAG FOR REQUIRED SCHEDULE UPDATE
    * WHENEVER CUSTOMER CALENDAR MAINTENANCE HAS BEEN USED */
   for each so_mstr where
            so_ship = shop_site and
            so_sched
   no-lock:
      do transaction:
         for each sod_det where
                  sod_nbr = so_nbr and
                  sod_sched_chgd = no
         no-lock:
            find soddet where recid(soddet) = recid(sod_det)
            exclusive-lock no-error.
            if available soddet then
               soddet.sod_sched_chgd = yes.
         end.
      end.
   end.

end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* mainloop repeat */

status input.
